package vn.edu.saigontech.ncms.web.esl;

import java.util.Collection;

import vn.edu.saigontech.ncms.model.info.Offering;
import vn.edu.saigontech.ncms.service.LevelService;
import vn.edu.saigontech.ncms.service.OfferingService;
import vn.edu.saigontech.ncms.service.ProgramService;
import vn.edu.saigontech.ncms.util.DateUtil;
import vn.edu.saigontech.ncms.web.BaseAction;

@SuppressWarnings("serial")
public class OfferingAction extends BaseAction {
	
	private String name;
	private Long levelId;
	private String startDate;
	private String endDate;
	
	public String showSearch() {
		REQUEST().setAttribute("programs", ProgramService.INSTANCE.findAllAreActive());
		return SUCCESS;
	}
	
	public String search() {
		Offering offering = new Offering();
		offering.setName(this.name);
		offering.setLevel(LevelService.INSTANCE.findById(this.levelId));
		offering.setStartDate(DateUtil.fromString(this.startDate, this.i18n("format.date")));
		offering.setEndDate(DateUtil.fromString(this.endDate, this.i18n("format.date")));
		Collection<Offering> offerings = OfferingService.INSTANCE.find(offering);
		REQUEST().setAttribute("offerings", offerings);
		return SUCCESS;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Long getLevelId() {
		return levelId;
	}

	public void setLevelId(Long levelId) {
		this.levelId = levelId;
	}

	public String getStartDate() {
		return startDate;
	}

	public void setStartDate(String startDate) {
		this.startDate = startDate;
	}

	public String getEndDate() {
		return endDate;
	}

	public void setEndDate(String endDate) {
		this.endDate = endDate;
	}
}
